/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.gt.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.gt.dao.GtAnalysisDao;
import com.thinkgem.jeesite.modules.gt.entity.GtTecClear;

/**
 * 技术明白人信息Service
 * @author zad
 * @version 2018-03-26
 */
@Service
@Transactional(readOnly = true)
public class GtAnalysisService extends CrudService<GtAnalysisDao, GtTecClear> {

	/*全省经济林完成百分比*/
	public Map<String,String> forestTotalRate(Map<String,String> map)
	{
		return super.dao.forestTotalRate(map);
	}
	/*各地市经济林完成百分比*/
	public List<Map<String,String>> forestRegionRate(Map<String,String> map)
	{
		return super.dao.forestRegionRate(map);
	}
	
	/*全省经济林扶贫人完成百分比*/
	/*public Map<String,String> forestPeopleRate()
	{
		return super.dao.forestPeopleRate();
	}*/
	/*各地市经济林扶贫人完成百分比*/
	/*public List<Map<String,String>> forestRegionPeopleRate()
	{
		return super.dao.forestRegionPeopleRate();
	}*/
	
	/*全省护林员岗位扶贫人完成百分比*/
	public Map<String,String> postTotalRate(Map<String,String> map)
	{
		return super.dao.postTotalRate(map);
	}
	/*各地市护林员岗位扶贫人完成百分比*/
	public List<Map<String,String>> postRegionPeopleRate(Map<String,String> map)
	{
		return super.dao.postRegionPeopleRate(map);
	}
	
	/*全省龙头企业（合作社）扶贫完成百分比*/
	public Map<String,String> companyTotalRate(Map<String,String> map)
	{
		return super.dao.companyTotalRate(map);
	}
	/*各地市龙头企业（合作社）扶贫完成百分比*/
	public List<Map<String,String>> companyRegionRate(Map<String,String> map)
	{
		return super.dao.companyRegionRate(map);
	}
	
	
	
	/*各地市、区县科技下乡扶贫完成百分比，各地市，各区县需要单独统计，因为地市和区县都有自己的科技下乡活动*/
	public List<Map<String,String>> countryRegionRate(Map<String,String> map)
	{
		return super.dao.countryRegionRate(map);
	}
	
	/*全省林业政策统计，用于“总体进度一览表”，统计全省总量(政策总数及总人数)，包括地市和区县 */
	public Map<String,String> policyTotal(Map<String,String> map)
	{
		return super.dao.policyTotal(map);
	}
	
	/*全省龙头企业（合作社）统计，用于“总体进度一览表”，统计全省总量(政策总数及总人数)，包括地市和区县*/
	public Map<String,String> companyTotal(Map<String,String> map)
	{
		return super.dao.companyTotal(map);
	}
	
	/*地区科技下乡平均进度统计*/
	public Map<String,String> regionCountryTotal(Map<String,String> map)
	{
		return super.dao.regionCountryTotal(map);
	}
	
	/*全省林业政策统计，用于“总体进度一览表”，统计全省总量(政策总数及总人数)，包括地市和区县*/
	public Map<String,String> trainTotal(Map<String,String> map)
	{
		return super.dao.trainTotal(map);
	}
	
	/*全省林业技术明白人统计，用于“总体进度一览表”，统计全省总量(县、乡镇、村)*/
	public Map<String,String> clearTotal(Map<String,String> map)
	{
		return super.dao.clearTotal(map);
	}
	
	/*全区域（省、市、县）技术明白人统计，用于“总体进度一览表” */
	public Map<String,String> clearRegionTotal(Map<String,String> map)
	{
		return super.dao.clearRegionTotal(map);
	}
	
	/*全省工作月报统计，用于“总体进度一览表”，统计全省当月月报*/
	public Map<String,String> reportTotal(Map<String,String> map)
	{
		return super.dao.reportTotal(map);
	}
	
	/*全省信息宣传统计，用于“总体进度一览表”，统计全省信息宣传量 */
	public Map<String,String> deliverTotal(Map<String,String> map)
	{
		return super.dao.deliverTotal(map);
	}
	
	/*各地市、区县技术明白人完成百分比，各地市，各区县需要单独统计，因为地市和区县技术明白人统计方式不一样*/
	public List<Map<String,String>> clearRegionRate(Map<String,String> map)
	{
		return super.dao.clearRegionRate(map);
	}
	
	/*各地市、区县技术明白人完成百分比，各地市，各区县需要单独统计，因为地市和区县技术明白人统计方式不一样*/
	public List<Map<String,String>> clearRegionCountryRate(Map<String,String> map)
	{
		return super.dao.clearRegionCountryRate(map);
	}
	
	/*各地市、区县技术明白人完成百分比，各地市，各区县需要单独统计，因为地市和区县技术明白人统计方式不一样*/
	public List<Map<String,String>> clearRegionTownRate(Map<String,String> map)
	{
		return super.dao.clearRegionTownRate(map);
	}
	
	/*各个地市、区县所有进度统计 add by zad 2018-05-02*/
	public List<Map<String,String>> fpRegionAllRate(Map<String,String> map)
	{
		return super.dao.fpRegionAllRate(map);
	}
	
	/*下级单位区县、乡镇、村技术明白人完成百分比*/
	public List<Map<String,String>> regionCountyTownClearRate(Map<String,String> map)
	{
		return super.dao.regionCountyTownClearRate(map);
	}
	
	// 解析同级数据为chart格式数据串
	public Map<String,String> parseMapChart(List<Map<String,String>> forestRegionList, String key1,String key2,String key3,String key4)
	{
		Map<String,String> rs = new HashMap<String, String>();
		
		StringBuffer areaName = null;
		StringBuffer areaRate = null;
		StringBuffer peopleRate = null;
		StringBuffer key4Rate = null;
		
		
		for(Map<String,String> fMap : forestRegionList)
		{
			String name = null == fMap.get(key1)?"0" : String.valueOf(fMap.get(key1));
			String aRate = null == fMap.get(key2)?"0" : String.valueOf(fMap.get(key2));
			String pRate = null == fMap.get(key3)?"0" : String.valueOf(fMap.get(key3));
			String k4Rate = (StringUtils.isBlank(key4) || null == fMap.get(key4))?"0" : String.valueOf(fMap.get(key4));
			
			if(null == areaName)
			{
				areaName = new StringBuffer();
				areaName.append(pairString(name));
			}else
			{
				areaName.append(",").append(pairString(name));
			}
			
			if(null == areaRate)
			{
				areaRate = new StringBuffer();
				areaRate.append(aRate);
			}else
			{
				areaRate.append(",").append(aRate);
			}
			
			if(null == peopleRate)
			{
				peopleRate = new StringBuffer();
				peopleRate.append(pRate);
			}else
			{
				peopleRate.append(",").append(pRate);
			}
			
			if(null == key4Rate)
			{
				key4Rate = new StringBuffer();
				key4Rate.append(k4Rate);
			}else
			{
				key4Rate.append(",").append(k4Rate);
			}
		}
		
		rs.put(key1 + "s", areaName.toString());
		rs.put(key2 + "s", areaRate.toString());
		rs.put(key3 + "s", peopleRate.toString());
		rs.put(key4 + "s", key4Rate.toString());
		
		return rs;
	}
	
	// 将map中键值为key1的值修改为键值key2
	public Map<String,String> replaceKey(Map<String,String> map, String key1,String key2)
	{
		if(StringUtils.isBlank(key2))
		{
			return map;
		}
		if(null == map)
		{
			return null;
		}
		if(!map.containsKey(key1))
		{
			return map;
		}
		String key1v = map.get(key1);
		map.remove(key1);
		map.put(key2, key1v);
		return map;
	}
	
	public String pairString(String name)
	{
		if(StringUtils.isBlank(name))
		{
			return "'" + "'";
		}
		return "'" + name + "'";
	}
}